#include "WindSensor.h"

WindSensor::WindSensor(){
    _lastDirection = 0;
    _directionChanged = false;

    pinMode(62, INPUT);
}

void WindSensor::measureWindDirection(){
    _directionRaw = pulseIn(62, HIGH, 1500); //Hardcoded pin value
    _direction = _directionRaw*24/17*15/31/2;
    if(_direction > 180)_direction = _direction - 360;

    if(_direction != _lastDirection)
        _directionChanged = true;
    else
        _directionChanged = false;

    _lastDirection = _direction;
}

int32_t WindSensor::getWindDirection(){
    return _direction;
}

int32_t WindSensor::getWindDirectionRaw(){
    return _directionRaw;
}

bool WindSensor::directionChanged(){
    return _directionChanged;
}
